Skip to contentSkip to conversation

Change in openvpn[master]: socket: Create socket_util with non-socket functions

Openvpn-devel Applied flichtenheld (Code Review) 2 participants 6 messages Aug 28, 2025 – Aug 31, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1756396351000.I7393459b975fb9b3e0a42743f58645f769d1be5a@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1159?usp=email

to review the following change.

Change subject: socket: Create socket_util with non-socket functions
......................................................................

socket: Create socket_util with non-socket functions

This extracts a lot of the helper functions that do not actually work on sockets, but instead on addresses or similar.

This includes

- openvpn_getaddrinfo and related functions
- print_*
- setenv_*

And lots of the inline functions.

This move will make it easier to add unit tests
for these moved functions.

Change-Id I7393459b975fb9b3e0a42743f58645f769d1be5a

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/clinat.c
M src/openvpn/dhcp.c
M src/openvpn/dns.c
M src/openvpn/manage.h
M src/openvpn/misc.c
M src/openvpn/misc.h
M src/openvpn/mroute.c
M src/openvpn/mss.h
M src/openvpn/networking_iproute2.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/pool.c
M src/openvpn/socket.c
M src/openvpn/socket.h
A src/openvpn/socket_util.c
A src/openvpn/socket_util.h
M src/openvpn/ssl_common.h
M src/openvpn/tun.c

20 files changed, 1,443 insertions(+), 1,380 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/59/1159/1

CMakeLists.txt +2 -0
index 3866e21..45044af 100644
@@ -555,6 +555,8 @@
     src/openvpn/sig.h
     src/openvpn/socket.c
     src/openvpn/socket.h
+    src/openvpn/socket_util.c
+    src/openvpn/socket_util.h
     src/openvpn/socks.c
     src/openvpn/socks.h
     src/openvpn/ssl.c
src/openvpn/Makefile.am +1 -0
index 1e17c3f..217f897 100644
@@ -128,6 +128,7 @@
 	shaper.c shaper.h \
 	sig.c sig.h \
 	socket.c socket.h \
+	socket_util.c socket_util.h \
 	socks.c socks.h \
 	ssl.c ssl.h  ssl_backend.h \
 	ssl_openssl.c ssl_openssl.h \
src/openvpn/clinat.c +1 -1
index a303285..48a2057 100644
@@ -28,7 +28,7 @@
 
 #include "clinat.h"
 #include "proto.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "memdbg.h"
 
 static bool
src/openvpn/dhcp.c +1 -1
index 0a7689f..7abade5 100644
@@ -27,7 +27,7 @@
 #include "syshead.h"
 
 #include "dhcp.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "error.h"
 
 #include "memdbg.h"
src/openvpn/dns.c +1 -1
index 8e28c2b..8554089 100644
@@ -27,7 +27,7 @@
 #include "syshead.h"
 
 #include "dns.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "options.h"
 #include "run_command.h"
 
src/openvpn/manage.h +1 -1
index 083caf5..b8892c8 100644
@@ -48,7 +48,7 @@
 
 #include "misc.h"
 #include "event.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "mroute.h"
 
 #define MANAGEMENT_VERSION                  5
src/openvpn/misc.c +0 -21
index 17f7706..59bf52b 100644
@@ -72,27 +72,6 @@
 #endif
 }
 
-/*
- * Prepend a random string to hostname to prevent DNS caching.
- * For example, foo.bar.gov would be modified to <random-chars>.foo.bar.gov.
- * Of course, this requires explicit support in the DNS server (wildcard).
- */
-const char *
-hostname_randomize(const char *hostname, struct gc_arena *gc)
-{
-#define n_rnd_bytes 6
-
-    uint8_t rnd_bytes[n_rnd_bytes];
-    const char *rnd_str;
-    struct buffer hname = alloc_buf_gc(strlen(hostname) + sizeof(rnd_bytes) * 2 + 4, gc);
-
-    prng_bytes(rnd_bytes, sizeof(rnd_bytes));
-    rnd_str = format_hex_ex(rnd_bytes, sizeof(rnd_bytes), 40, 0, NULL, gc);
-    buf_printf(&hname, "%s.%s", rnd_str, hostname);
-    return BSTR(&hname);
-#undef n_rnd_bytes
-}
-
 #ifdef ENABLE_MANAGEMENT
 /* Get username/password from the management interface */
 static bool
src/openvpn/misc.h +0 -3
index 1b10cd9..e87fd85 100644
@@ -44,9 +44,6 @@
 
 const char **make_extended_arg_array(char **p, bool is_inline, struct gc_arena *gc);
 
-/* prepend a random prefix to hostname */
-const char *hostname_randomize(const char *hostname, struct gc_arena *gc);
-
 /*
  * Get and store a username/password
  */
src/openvpn/mroute.c +1 -1
index a598037..ab01874 100644
@@ -30,7 +30,7 @@
 #include "mroute.h"
 #include "proto.h"
 #include "error.h"
-#include "socket.h"
+#include "socket_util.h"
 
 #include "memdbg.h"
 
src/openvpn/mss.h +1 -0
index 05f12a7..bcbb5a8 100644
@@ -26,6 +26,7 @@
 #include "proto.h"
 #include "error.h"
 #include "mtu.h"
+#include "socket.h"
 #include "ssl_common.h"
 
 void mss_fixup_ipv4(struct buffer *buf, uint16_t maxmss);
src/openvpn/networking_iproute2.c +1 -1
index 0635b5d..e9be3a4 100644
@@ -30,7 +30,7 @@
 #include "misc.h"
 #include "openvpn.h"
 #include "run_command.h"
-#include "socket.h"
+#include "socket_util.h"
 
 #include <stdbool.h>
 #include <netinet/in.h>
src/openvpn/options.c +1 -1
index 648d526..74946a4 100644
@@ -45,7 +45,7 @@
 #include "ssl_ncp.h"
 #include "options.h"
 #include "misc.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "packet_id.h"
 #include "pkcs11.h"
 #include "win32.h"
src/openvpn/options.h +1 -1
index 4fa6800..44f3fc9 100644
@@ -33,7 +33,7 @@
 #include "mtu.h"
 #include "route.h"
 #include "tun.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "plugin.h"
 #include "manage.h"
 #include "proxy.h"
src/openvpn/pool.c +1 -1
index a41364a..fde6cea 100644
@@ -29,7 +29,7 @@
 #include "pool.h"
 #include "buffer.h"
 #include "error.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "otime.h"
 
 #include "memdbg.h"
src/openvpn/socket.c +0 -883

895 lines not on this page · raw message

src/openvpn/socket.h +1 -462

505 lines not on this page · raw message

src/openvpn/socket_util.c new file +936 -0

936 lines not on this page · raw message

src/openvpn/socket_util.h new file +491 -0

491 lines not on this page · raw message

src/openvpn/ssl_common.h +1 -1
index e8fde86..428bf5a 100644
@@ -30,7 +30,7 @@
 #define SSL_COMMON_H_
 
 #include "session_id.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "packet_id.h"
 #include "crypto.h"
 #include "options.h"
src/openvpn/tun.c +1 -1
index f54b608..6c3096b 100644
@@ -39,7 +39,7 @@
 #include "fdmisc.h"
 #include "common.h"
 #include "run_command.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "manage.h"
 #include "route.h"
 #include "win32.h"

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1159?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7393459b975fb9b3e0a42743f58645f769d1be5a
Gerrit-Change-Number: 1159
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/1159?usp=email )

Change subject: socket: Create socket_util with non-socket functions
......................................................................

Patch Set 1: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1159?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7393459b975fb9b3e0a42743f58645f769d1be5a
Gerrit-Change-Number: 1159
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sun, 31 Aug 2025 15:59:07 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#3 lore raw

PATCH 1/1 socket: Create socket_util with non-socket functions

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

This extracts a lot of the helper functions that do not actually work on sockets, but instead on addresses or similar.

This includes

- openvpn_getaddrinfo and related functions
- print_*
- setenv_*

And lots of the inline functions.

This move will make it easier to add unit tests
for these moved functions.

Change-Id I7393459b975fb9b3e0a42743f58645f769d1be5a

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1159
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>

CMakeLists.txt +2 -0
index 3866e21..45044af 100644
@@ -555,6 +555,8 @@
     src/openvpn/sig.h
     src/openvpn/socket.c
     src/openvpn/socket.h
+    src/openvpn/socket_util.c
+    src/openvpn/socket_util.h
     src/openvpn/socks.c
     src/openvpn/socks.h
     src/openvpn/ssl.c
src/openvpn/Makefile.am +1 -0
index 1e17c3f..217f897 100644
@@ -128,6 +128,7 @@
 	shaper.c shaper.h \
 	sig.c sig.h \
 	socket.c socket.h \
+	socket_util.c socket_util.h \
 	socks.c socks.h \
 	ssl.c ssl.h  ssl_backend.h \
 	ssl_openssl.c ssl_openssl.h \
src/openvpn/clinat.c +1 -1
index a303285..48a2057 100644
@@ -28,7 +28,7 @@
 
 #include "clinat.h"
 #include "proto.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "memdbg.h"
 
 static bool
src/openvpn/dhcp.c +1 -1
index 0a7689f..7abade5 100644
@@ -27,7 +27,7 @@
 #include "syshead.h"
 
 #include "dhcp.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "error.h"
 
 #include "memdbg.h"
src/openvpn/dns.c +1 -1
index 8e28c2b..8554089 100644
@@ -27,7 +27,7 @@
 #include "syshead.h"
 
 #include "dns.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "options.h"
 #include "run_command.h"
 
src/openvpn/manage.h +1 -1
index 083caf5..b8892c8 100644
@@ -48,7 +48,7 @@
 
 #include "misc.h"
 #include "event.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "mroute.h"
 
 #define MANAGEMENT_VERSION                  5
src/openvpn/misc.c +0 -21
index 17f7706..59bf52b 100644
@@ -72,27 +72,6 @@
 #endif
 }
 
-/*
- * Prepend a random string to hostname to prevent DNS caching.
- * For example, foo.bar.gov would be modified to <random-chars>.foo.bar.gov.
- * Of course, this requires explicit support in the DNS server (wildcard).
- */
-const char *
-hostname_randomize(const char *hostname, struct gc_arena *gc)
-{
-#define n_rnd_bytes 6
-
-    uint8_t rnd_bytes[n_rnd_bytes];
-    const char *rnd_str;
-    struct buffer hname = alloc_buf_gc(strlen(hostname) + sizeof(rnd_bytes) * 2 + 4, gc);
-
-    prng_bytes(rnd_bytes, sizeof(rnd_bytes));
-    rnd_str = format_hex_ex(rnd_bytes, sizeof(rnd_bytes), 40, 0, NULL, gc);
-    buf_printf(&hname, "%s.%s", rnd_str, hostname);
-    return BSTR(&hname);
-#undef n_rnd_bytes
-}
-
 #ifdef ENABLE_MANAGEMENT
 /* Get username/password from the management interface */
 static bool
src/openvpn/misc.h +0 -3
index 1b10cd9..e87fd85 100644
@@ -44,9 +44,6 @@
 
 const char **make_extended_arg_array(char **p, bool is_inline, struct gc_arena *gc);
 
-/* prepend a random prefix to hostname */
-const char *hostname_randomize(const char *hostname, struct gc_arena *gc);
-
 /*
  * Get and store a username/password
  */
src/openvpn/mroute.c +1 -1
index a598037..ab01874 100644
@@ -30,7 +30,7 @@
 #include "mroute.h"
 #include "proto.h"
 #include "error.h"
-#include "socket.h"
+#include "socket_util.h"
 
 #include "memdbg.h"
 
src/openvpn/mss.h +1 -0
index 05f12a7..bcbb5a8 100644
@@ -26,6 +26,7 @@
 #include "proto.h"
 #include "error.h"
 #include "mtu.h"
+#include "socket.h"
 #include "ssl_common.h"
 
 void mss_fixup_ipv4(struct buffer *buf, uint16_t maxmss);
src/openvpn/networking_iproute2.c +1 -1
index 0635b5d..e9be3a4 100644
@@ -30,7 +30,7 @@
 #include "misc.h"
 #include "openvpn.h"
 #include "run_command.h"
-#include "socket.h"
+#include "socket_util.h"
 
 #include <stdbool.h>
 #include <netinet/in.h>
src/openvpn/options.c +1 -1
index 648d526..74946a4 100644
@@ -45,7 +45,7 @@
 #include "ssl_ncp.h"
 #include "options.h"
 #include "misc.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "packet_id.h"
 #include "pkcs11.h"
 #include "win32.h"
src/openvpn/options.h +1 -1
index 4fa6800..44f3fc9 100644
@@ -33,7 +33,7 @@
 #include "mtu.h"
 #include "route.h"
 #include "tun.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "plugin.h"
 #include "manage.h"
 #include "proxy.h"
src/openvpn/pool.c +1 -1
index a41364a..fde6cea 100644
@@ -29,7 +29,7 @@
 #include "pool.h"
 #include "buffer.h"
 #include "error.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "otime.h"
 
 #include "memdbg.h"
src/openvpn/socket.c +0 -883

895 lines not on this page · raw message

src/openvpn/socket.h +1 -462

505 lines not on this page · raw message

src/openvpn/socket_util.c new file +936 -0

936 lines not on this page · raw message

src/openvpn/socket_util.h new file +491 -0

491 lines not on this page · raw message

src/openvpn/ssl_common.h +1 -1
index e8fde86..428bf5a 100644
@@ -30,7 +30,7 @@
 #define SSL_COMMON_H_
 
 #include "session_id.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "packet_id.h"
 #include "crypto.h"
 #include "options.h"
src/openvpn/tun.c +1 -1
index f54b608..6c3096b 100644
@@ -39,7 +39,7 @@
 #include "fdmisc.h"
 #include "common.h"
 #include "run_command.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "manage.h"
 #include "route.h"
 #include "win32.h"
Applied
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: socket: Create socket_util with non-socket functions

Decluttering socket.c is a good thing (and introducing a unit test in #1160 quite welcome). Stared at the change with "git show --color-moved" and it's quite clear that this is only moves, no code change - and the BBs confirm that it still compiles and passes all relevant tests.

Pushed to GHA for good measure (all green).

Your patch has been applied to the master branch.

commit cdd61ffbccfcc81b560d2bec54c9a431ab6a025a

Author: Frank Lichtenheld
Date:   Sun Aug 31 17:59:32 2025 +0200
     socket: Create socket_util with non-socket functions

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Gert Doering <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg32727.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1159?usp=email )

Change subject: socket: Create socket_util with non-socket functions
......................................................................

socket: Create socket_util with non-socket functions

This extracts a lot of the helper functions that do not actually work on sockets, but instead on addresses or similar.

This includes

- openvpn_getaddrinfo and related functions
- print_*
- setenv_*

And lots of the inline functions.

This move will make it easier to add unit tests
for these moved functions.

Change-Id I7393459b975fb9b3e0a42743f58645f769d1be5a

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg32727.html

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/clinat.c
M src/openvpn/dhcp.c
M src/openvpn/dns.c
M src/openvpn/manage.h
M src/openvpn/misc.c
M src/openvpn/misc.h
M src/openvpn/mroute.c
M src/openvpn/mss.h
M src/openvpn/networking_iproute2.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/pool.c
M src/openvpn/socket.c
M src/openvpn/socket.h
A src/openvpn/socket_util.c
A src/openvpn/socket_util.h
M src/openvpn/ssl_common.h
M src/openvpn/tun.c

20 files changed, 1,443 insertions(+), 1,380 deletions(-)
CMakeLists.txt +2 -0
index 3866e21..45044af 100644
@@ -555,6 +555,8 @@
     src/openvpn/sig.h
     src/openvpn/socket.c
     src/openvpn/socket.h
+    src/openvpn/socket_util.c
+    src/openvpn/socket_util.h
     src/openvpn/socks.c
     src/openvpn/socks.h
     src/openvpn/ssl.c
src/openvpn/Makefile.am +1 -0
index 1e17c3f..217f897 100644
@@ -128,6 +128,7 @@
 	shaper.c shaper.h \
 	sig.c sig.h \
 	socket.c socket.h \
+	socket_util.c socket_util.h \
 	socks.c socks.h \
 	ssl.c ssl.h  ssl_backend.h \
 	ssl_openssl.c ssl_openssl.h \
src/openvpn/clinat.c +1 -1
index a303285..48a2057 100644
@@ -28,7 +28,7 @@
 
 #include "clinat.h"
 #include "proto.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "memdbg.h"
 
 static bool
src/openvpn/dhcp.c +1 -1
index 0a7689f..7abade5 100644
@@ -27,7 +27,7 @@
 #include "syshead.h"
 
 #include "dhcp.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "error.h"
 
 #include "memdbg.h"
src/openvpn/dns.c +1 -1
index 8e28c2b..8554089 100644
@@ -27,7 +27,7 @@
 #include "syshead.h"
 
 #include "dns.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "options.h"
 #include "run_command.h"
 
src/openvpn/manage.h +1 -1
index 083caf5..b8892c8 100644
@@ -48,7 +48,7 @@
 
 #include "misc.h"
 #include "event.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "mroute.h"
 
 #define MANAGEMENT_VERSION                  5
src/openvpn/misc.c +0 -21
index 17f7706..59bf52b 100644
@@ -72,27 +72,6 @@
 #endif
 }
 
-/*
- * Prepend a random string to hostname to prevent DNS caching.
- * For example, foo.bar.gov would be modified to <random-chars>.foo.bar.gov.
- * Of course, this requires explicit support in the DNS server (wildcard).
- */
-const char *
-hostname_randomize(const char *hostname, struct gc_arena *gc)
-{
-#define n_rnd_bytes 6
-
-    uint8_t rnd_bytes[n_rnd_bytes];
-    const char *rnd_str;
-    struct buffer hname = alloc_buf_gc(strlen(hostname) + sizeof(rnd_bytes) * 2 + 4, gc);
-
-    prng_bytes(rnd_bytes, sizeof(rnd_bytes));
-    rnd_str = format_hex_ex(rnd_bytes, sizeof(rnd_bytes), 40, 0, NULL, gc);
-    buf_printf(&hname, "%s.%s", rnd_str, hostname);
-    return BSTR(&hname);
-#undef n_rnd_bytes
-}
-
 #ifdef ENABLE_MANAGEMENT
 /* Get username/password from the management interface */
 static bool
src/openvpn/misc.h +0 -3
index 1b10cd9..e87fd85 100644
@@ -44,9 +44,6 @@
 
 const char **make_extended_arg_array(char **p, bool is_inline, struct gc_arena *gc);
 
-/* prepend a random prefix to hostname */
-const char *hostname_randomize(const char *hostname, struct gc_arena *gc);
-
 /*
  * Get and store a username/password
  */
src/openvpn/mroute.c +1 -1
index a598037..ab01874 100644
@@ -30,7 +30,7 @@
 #include "mroute.h"
 #include "proto.h"
 #include "error.h"
-#include "socket.h"
+#include "socket_util.h"
 
 #include "memdbg.h"
 
src/openvpn/mss.h +1 -0
index 05f12a7..bcbb5a8 100644
@@ -26,6 +26,7 @@
 #include "proto.h"
 #include "error.h"
 #include "mtu.h"
+#include "socket.h"
 #include "ssl_common.h"
 
 void mss_fixup_ipv4(struct buffer *buf, uint16_t maxmss);
src/openvpn/networking_iproute2.c +1 -1
index 0635b5d..e9be3a4 100644
@@ -30,7 +30,7 @@
 #include "misc.h"
 #include "openvpn.h"
 #include "run_command.h"
-#include "socket.h"
+#include "socket_util.h"
 
 #include <stdbool.h>
 #include <netinet/in.h>
src/openvpn/options.c +1 -1
index 648d526..74946a4 100644
@@ -45,7 +45,7 @@
 #include "ssl_ncp.h"
 #include "options.h"
 #include "misc.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "packet_id.h"
 #include "pkcs11.h"
 #include "win32.h"
src/openvpn/options.h +1 -1
index 4fa6800..44f3fc9 100644
@@ -33,7 +33,7 @@
 #include "mtu.h"
 #include "route.h"
 #include "tun.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "plugin.h"
 #include "manage.h"
 #include "proxy.h"
src/openvpn/pool.c +1 -1
index a41364a..fde6cea 100644
@@ -29,7 +29,7 @@
 #include "pool.h"
 #include "buffer.h"
 #include "error.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "otime.h"
 
 #include "memdbg.h"
src/openvpn/socket.c +0 -883

895 lines not on this page · raw message

src/openvpn/socket.h +1 -462

505 lines not on this page · raw message

src/openvpn/socket_util.c new file +936 -0

936 lines not on this page · raw message

src/openvpn/socket_util.h new file +491 -0

491 lines not on this page · raw message

src/openvpn/ssl_common.h +1 -1
index e8fde86..428bf5a 100644
@@ -30,7 +30,7 @@
 #define SSL_COMMON_H_
 
 #include "session_id.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "packet_id.h"
 #include "crypto.h"
 #include "options.h"
src/openvpn/tun.c +1 -1
index f54b608..6c3096b 100644
@@ -39,7 +39,7 @@
 #include "fdmisc.h"
 #include "common.h"
 #include "run_command.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "manage.h"
 #include "route.h"
 #include "win32.h"

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1159?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7393459b975fb9b3e0a42743f58645f769d1be5a
Gerrit-Change-Number: 1159
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged

#6 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#2) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1159?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by cron2

Change subject: socket: Create socket_util with non-socket functions
......................................................................

socket: Create socket_util with non-socket functions

This extracts a lot of the helper functions that do not actually work on sockets, but instead on addresses or similar.

This includes

- openvpn_getaddrinfo and related functions
- print_*
- setenv_*

And lots of the inline functions.

This move will make it easier to add unit tests
for these moved functions.

Change-Id I7393459b975fb9b3e0a42743f58645f769d1be5a

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg32727.html

---
M CMakeLists.txt
M src/openvpn/Makefile.am
M src/openvpn/clinat.c
M src/openvpn/dhcp.c
M src/openvpn/dns.c
M src/openvpn/manage.h
M src/openvpn/misc.c
M src/openvpn/misc.h
M src/openvpn/mroute.c
M src/openvpn/mss.h
M src/openvpn/networking_iproute2.c
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/pool.c
M src/openvpn/socket.c
M src/openvpn/socket.h
A src/openvpn/socket_util.c
A src/openvpn/socket_util.h
M src/openvpn/ssl_common.h
M src/openvpn/tun.c

20 files changed, 1,443 insertions(+), 1,380 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/59/1159/2

CMakeLists.txt +2 -0
index 3866e21..45044af 100644
@@ -555,6 +555,8 @@
     src/openvpn/sig.h
     src/openvpn/socket.c
     src/openvpn/socket.h
+    src/openvpn/socket_util.c
+    src/openvpn/socket_util.h
     src/openvpn/socks.c
     src/openvpn/socks.h
     src/openvpn/ssl.c
src/openvpn/Makefile.am +1 -0
index 1e17c3f..217f897 100644
@@ -128,6 +128,7 @@
 	shaper.c shaper.h \
 	sig.c sig.h \
 	socket.c socket.h \
+	socket_util.c socket_util.h \
 	socks.c socks.h \
 	ssl.c ssl.h  ssl_backend.h \
 	ssl_openssl.c ssl_openssl.h \
src/openvpn/clinat.c +1 -1
index a303285..48a2057 100644
@@ -28,7 +28,7 @@
 
 #include "clinat.h"
 #include "proto.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "memdbg.h"
 
 static bool
src/openvpn/dhcp.c +1 -1
index 0a7689f..7abade5 100644
@@ -27,7 +27,7 @@
 #include "syshead.h"
 
 #include "dhcp.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "error.h"
 
 #include "memdbg.h"
src/openvpn/dns.c +1 -1
index 8e28c2b..8554089 100644
@@ -27,7 +27,7 @@
 #include "syshead.h"
 
 #include "dns.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "options.h"
 #include "run_command.h"
 
src/openvpn/manage.h +1 -1
index 083caf5..b8892c8 100644
@@ -48,7 +48,7 @@
 
 #include "misc.h"
 #include "event.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "mroute.h"
 
 #define MANAGEMENT_VERSION                  5
src/openvpn/misc.c +0 -21
index 17f7706..59bf52b 100644
@@ -72,27 +72,6 @@
 #endif
 }
 
-/*
- * Prepend a random string to hostname to prevent DNS caching.
- * For example, foo.bar.gov would be modified to <random-chars>.foo.bar.gov.
- * Of course, this requires explicit support in the DNS server (wildcard).
- */
-const char *
-hostname_randomize(const char *hostname, struct gc_arena *gc)
-{
-#define n_rnd_bytes 6
-
-    uint8_t rnd_bytes[n_rnd_bytes];
-    const char *rnd_str;
-    struct buffer hname = alloc_buf_gc(strlen(hostname) + sizeof(rnd_bytes) * 2 + 4, gc);
-
-    prng_bytes(rnd_bytes, sizeof(rnd_bytes));
-    rnd_str = format_hex_ex(rnd_bytes, sizeof(rnd_bytes), 40, 0, NULL, gc);
-    buf_printf(&hname, "%s.%s", rnd_str, hostname);
-    return BSTR(&hname);
-#undef n_rnd_bytes
-}
-
 #ifdef ENABLE_MANAGEMENT
 /* Get username/password from the management interface */
 static bool
src/openvpn/misc.h +0 -3
index 1b10cd9..e87fd85 100644
@@ -44,9 +44,6 @@
 
 const char **make_extended_arg_array(char **p, bool is_inline, struct gc_arena *gc);
 
-/* prepend a random prefix to hostname */
-const char *hostname_randomize(const char *hostname, struct gc_arena *gc);
-
 /*
  * Get and store a username/password
  */
src/openvpn/mroute.c +1 -1
index a598037..ab01874 100644
@@ -30,7 +30,7 @@
 #include "mroute.h"
 #include "proto.h"
 #include "error.h"
-#include "socket.h"
+#include "socket_util.h"
 
 #include "memdbg.h"
 
src/openvpn/mss.h +1 -0
index 05f12a7..bcbb5a8 100644
@@ -26,6 +26,7 @@
 #include "proto.h"
 #include "error.h"
 #include "mtu.h"
+#include "socket.h"
 #include "ssl_common.h"
 
 void mss_fixup_ipv4(struct buffer *buf, uint16_t maxmss);
src/openvpn/networking_iproute2.c +1 -1
index 0635b5d..e9be3a4 100644
@@ -30,7 +30,7 @@
 #include "misc.h"
 #include "openvpn.h"
 #include "run_command.h"
-#include "socket.h"
+#include "socket_util.h"
 
 #include <stdbool.h>
 #include <netinet/in.h>
src/openvpn/options.c +1 -1
index 648d526..74946a4 100644
@@ -45,7 +45,7 @@
 #include "ssl_ncp.h"
 #include "options.h"
 #include "misc.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "packet_id.h"
 #include "pkcs11.h"
 #include "win32.h"
src/openvpn/options.h +1 -1
index 4fa6800..44f3fc9 100644
@@ -33,7 +33,7 @@
 #include "mtu.h"
 #include "route.h"
 #include "tun.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "plugin.h"
 #include "manage.h"
 #include "proxy.h"
src/openvpn/pool.c +1 -1
index a41364a..fde6cea 100644
@@ -29,7 +29,7 @@
 #include "pool.h"
 #include "buffer.h"
 #include "error.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "otime.h"
 
 #include "memdbg.h"
src/openvpn/socket.c +0 -883

895 lines not on this page · raw message

src/openvpn/socket.h +1 -462

505 lines not on this page · raw message

src/openvpn/socket_util.c new file +936 -0

936 lines not on this page · raw message

src/openvpn/socket_util.h new file +491 -0

491 lines not on this page · raw message

src/openvpn/ssl_common.h +1 -1
index e8fde86..428bf5a 100644
@@ -30,7 +30,7 @@
 #define SSL_COMMON_H_
 
 #include "session_id.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "packet_id.h"
 #include "crypto.h"
 #include "options.h"
src/openvpn/tun.c +1 -1
index f54b608..6c3096b 100644
@@ -39,7 +39,7 @@
 #include "fdmisc.h"
 #include "common.h"
 #include "run_command.h"
-#include "socket.h"
+#include "socket_util.h"
 #include "manage.h"
 #include "route.h"
 #include "win32.h"

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1159?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I7393459b975fb9b3e0a42743f58645f769d1be5a
Gerrit-Change-Number: 1159
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset